package ihis.tms.server.service.item;

import ihis.core.service.RequestMessage;
import ihis.core.service.ResponseMessage;
import ihis.model.GeneralFilter;
import ihis.model.IHISConstants;
import ihis.model.PredictedCurve;
import ihis.tms.server.redmine.db.TMSDatabase;
import ihis.tms.server.service.IService;

import java.util.Vector;

public class PredictedCurveListService implements IService {

	@Override
	public ResponseMessage run(RequestMessage requestMessage) {
		// TODO Auto-generated method stub
		GeneralFilter filter = (GeneralFilter) requestMessage.getParameter("filter");
		ResponseMessage responseMessage = new ResponseMessage();
		
		try {
			if(filter == null)
			{
				responseMessage.setOk(false);
			}
			else
			{
				Vector<PredictedCurve> result = null;
				if(filter.getOwnerType() == IHISConstants.OWNERTYPE_PERSON)
					result = TMSDatabase.getPersonalPredictedCurves(filter);
				else if(filter.getOwnerType() == IHISConstants.OWNERTYPE_TEAM)
					result = TMSDatabase.getTeamPredictedCurves(filter);
				responseMessage.setOk(true);
				responseMessage.setResult(result);				
			}
		} catch (Exception e){
			responseMessage.setOk(false);
			e.printStackTrace();
		}
		return responseMessage;
	}

}
